#include <time.h>
#include <cstdlib>
#include <sstream>
#include "BipartiteGraph.h"

using namespace std;

BipartiteGraph::BipartiteGraph()
{
}

BipartiteGraph::BipartiteGraph(int taille, double p )
{ 
  srand(time(NULL));
  int r; 
  for (int i = 0; i < taille; ++i)
    {
      r = rand() % 100; 
      if(r<50)
	partition1.push_back(addVertex());
      else
	partition2.push_back(addVertex());

    }

  for (int i = 0; i < partition1.size(); ++i)
    {
      for (int j = 0; j < partition2.size(); ++j)
	{
	  if (rand() / (double)RAND_MAX < p) 
	    {
	      addEdge(partition1[i], partition2[j]);
	    }
	}
    }
}

BipartiteGraph::BipartiteGraph(BipartiteGraph& other) : AbstractGraph(other), partition1(other.partition1), partition2(other.partition2)
{
}

string BipartiteGraph::toString()
{
  cout << "\nPartition1 : ";
  for (int i = 0; i < partition1.size(); i++)
    {
      cout << partition1[i] << " ";
    }
  cout << "\nPartition2 : ";
  for (int i = 0; i < partition2.size(); i++)
    {
      cout << partition2[i] << " ";
    }
  cout << endl;
  
  std::ostringstream s;
  for (int i = 0; i < adgencyList.size(); i++) 
    {
      s << i + 1 << ":";
      for (int j = 0; j < adgencyList[i].size(); j++) 
	{
	  s << " " << adgencyList[i][j];
	}
      s << "\n";
    }
  return s.str();
}

std::vector<int>& BipartiteGraph::getPartition1()
{
  return partition1;
}

std::vector<int>& BipartiteGraph::getPartition2()
{
  return partition2;
}
